package com.huaxin.hxcloud.Adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.huaxin.common.Entity.RepairTaskInfo;
import com.huaxin.common.utils.Util;
import com.huaxin.hxcloud.R;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author lwjing
 * @date 2018/3/29
 * @Desc $desc$
 * Copyright HUAXIN DATA. All rights reserved.
 */
public class RepairupCheckAdapter extends BaseQuickAdapter<RepairTaskInfo, BaseViewHolder> {

    public RepairupCheckAdapter(int layoutResId, @Nullable List<RepairTaskInfo> data) {
        super(R.layout.item_repairup_check, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, RepairTaskInfo repairTaskInfo) {
        //        state 任务单状态:0、未派工;1、已派工;2、处理中;3已完成
        //        taskType 任务单类型:0设备巡检;1设备抢修;2设备维修;3设备维护;4拖泥;5养护  (4 5 保养，其他维修)
        //        priLevel 任务单优先级:0低1中2高3紧急4立刻     
        View left_view = baseViewHolder.getView(R.id.view);
        TextView tv_task_type = baseViewHolder.getView(R.id.tv_task_type);
        TextView tv_worktask_name = baseViewHolder.getView(R.id.tv_worktask_name);
        TextView tv_task_code = baseViewHolder.getView(R.id.tv_task_code);
        TextView tv_who_report = baseViewHolder.getView(R.id.tv_who_report);
        TextView tv_create_time = baseViewHolder.getView(R.id.tv_create_time);
        TextView tv_end_time = baseViewHolder.getView(R.id.tv_end_time);
        TextView tv_task_des = baseViewHolder.getView(R.id.tv_task_des);

        tv_worktask_name.setText(repairTaskInfo.getTitle());
        loadText(tv_task_code,"工单编号",repairTaskInfo.getTaskCode());
        loadText(tv_who_report,"负责人",repairTaskInfo.getCreateUser());
        loadText(tv_create_time,"创建时间",dateFormat(repairTaskInfo.getCreateDate()));
        loadText(tv_end_time,"截至时间",repairTaskInfo.getRequireDate());
        loadText(tv_task_des,"描述",repairTaskInfo.getDescription());

        if (repairTaskInfo.getTaskType() == 4 || repairTaskInfo.getTaskType() ==5){
            //保养
            tv_task_type.setText("保养单");
            tv_task_type.setSelected(true);
            left_view.setBackgroundColor(mContext.getResources().getColor(R.color.view_blue));
        }else{
            tv_task_type.setText("维修单");
            tv_task_type.setSelected(false);
            left_view.setBackgroundColor(mContext.getResources().getColor(R.color.view_green));
        }


    }

    public void loadText(TextView textView,String label,String def){
        if (textView ==null){
            return;
        }
        if (Util.checkNull(def)){
            textView.setText(label+": ");
        }else{
            textView.setText(label+": "+def);
        }
    }

    public String dateFormat(Long realStartDate) {
        String pattern="yyyy年MM月dd日";
        if (Util.checkNull(realStartDate)) {
            return null;
        }
        return new SimpleDateFormat(pattern).format(new Date(realStartDate));
    }
}
